// pages/geo/geo.js
var amapFile = require('/lib/amap-wx.130.js');  //引入高德js
var config = require('/lib/config.js');   //引用我们的配置文件
const app = getApp()
var markersData = [];
Page({
  data: {
    markers: [],
    latitude: '',
    longitude: '',
    textData: {},
    adcode:'',
    list:[],
    longitude: 117.99683380126953,  //默认定位经度
    latitude: 29.902965545654297,   //默认定位纬度
    markers: [
    //胡文光牌楼1
    {
        id: 0,
        iconPath: "/image/1.jpg",
        latitude: 29.901418539947255,
        longitude: 117.99300213072584,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
    },
      //追慕堂1
      {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.903394910739678,
        longitude: 117.99543757651136,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
      },
    //笃谊庭1
      {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.90368322507697,
        longitude: 117.99599011156843,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
      },
    //敬爱堂1
    {
      id: 2,
      iconPath: "/image/1.jpg",
      latitude: 29.902771776885785,
      longitude: 117.99681086752699,
      width: 20,
      height: 20,
      placeName:"胡文光牌楼"
    },
    //走马楼1
      {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.901623154260975,
        longitude: 117.9924174091606,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
      },
    //旷古斋1
       {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.902320699938368,
         longitude: 117.99434323523329,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
      },
      //瑞玉庭1
      {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.902757826072474,
        longitude: 117.99524445746229,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
      },
      //笃敬堂1
      {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.903334457624798,
        longitude: 117.9975511572151,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
      },
    //西园1
       {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.902567164908753,
        longitude: 117.99587209437178,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
      },
    //东园1
    {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.902567164908778,
        longitude: 117.99606521342085,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
      },
    //惇仁堂1
    {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.90185101972579,
        longitude: 117.99823243830488,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
      },
    //履福堂
    {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.902965545654297,
        longitude: 117.99683380126953,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
      },
    //膺福堂1
    {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.903194950297152,
        longitude: 117.99763698790358,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
      },
      //仰高堂1
      {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.90352046708557,
        longitude: 117.99718101237104,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
        },
    //尚德堂1
    {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.90338561025969,
        longitude: 117.99708445284651,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
      },
    //大夫第1
    {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.902799678485792,
        longitude:  117.99638707850264,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
      },
    //迪吉堂1
    {
        id: 1,
        iconPath: "/image/1.jpg",
        latitude: 29.903529767545763 ,
        longitude: 117.99579699251936 ,
        width: 20,
        height: 20,
        placeName:"胡文光牌楼"
      }]
  },
  
  weather: function(){
    wx.navigateTo({
      url: '/pages/mweather/mweather',
    })
  },
// 地图
  makertap: function(e) {
    var id = e.markerId;
    var that = this;
    that.showMarkerInfo(markersData,id);
    that.changeMarkerColor(markersData,id);
    console.log('查看makersdata内容',markersData)
  },
  onLoad: function() {
    var self = this;
    var that = this;
    var myAmapFun = new amapFile.AMapWX({key: "04690d6167e1ac044bef1f45a67c7eca"});



    // 地标
    wx.getLocation({
        type: "wgs84",
        success: function (res) {
          var latitude = res.data.latitude;
          var longitude = res.data.longitude;
          console.log("经度",latitude,longitude);
          that.setData({
            latitude: res.latitude,
            longitude: res.longitude,
            
            markers: [{
              latitude:res.latitude,
              longitude: res.longitude,
            }]
          }),console.log('经度纬度',res)
        }
      });
// 设置西递村的标
    myAmapFun.getPoiAround({
      success: function(data){
        var that = this
        markersData = data.markers;
        that.setData({
          markers: markersData
        });
        that.setData({
          latitude: markersData[0].latitude
        });
        console.log('maker',markersData)
        that.setData({
          longitude: markersData[0].longitude
        });
      },
      fail (info){
        var that = this
        wx.showModal({title:info.errMsg})
      },
    });
  },

  
  //地图
  showMarkerInfo: function(data,i){
    var that = this;
    that.setData({
      textData: {
        name: data[i].name,
        desc: data[i].address
      }
    });
  },
  changeMarkerColor: function(data,i){
    var that = this;
    var markers = [];
    for(var j = 0; j < data.length; j++){
      if(j==i){
        data[j].iconPath = "https://636c-cloud1-3g27h0fqe967f01e-1311565349.tcb.qcloud.la/images/02.png?sign=449ea2f380973c7f533263f832cdafd3&t=1655540094"; //如：..­/..­/img/marker_checked.png
      }else{
        data[j].iconPath = "https://636c-cloud1-3g27h0fqe967f01e-1311565349.tcb.qcloud.la/images/02.png?sign=449ea2f380973c7f533263f832cdafd3&t=1655540094"; //如：..­/..­/img/marker.png
      }
      markers.push(data[j]);
    }
    that.setData({
      markers: markers
    });
  },
  onReady: function () {

}

})
